package calbs.socket.tool;/**
 * Created by zhangqin on 2017/8/22.
 */

import calbs.socket.exception.AnalySocketException;
import calbs.socket.exception.AnalySocketExceptionEmum;

import java.math.BigDecimal;

/**
 * @author
 * @create 2017-08-22 14:43
 **/
public final class LatLngTool {
    public static final int LAT_LNG_POINT = 1000000;
    public static final int HEIGHT_POINT = 10000;
    public static final int DIRECTION_POINT = 100;

    public static String getLatLngByOld(Integer point){
       return getLatLngByOld(Long.parseLong(point.toString()));
    }

    public static String getHeightByOld(Integer height){
        return new BigDecimal(height).divide(new BigDecimal(HEIGHT_POINT),2,   BigDecimal.ROUND_HALF_UP).toPlainString();
    }
    public static String geDirectionByOld(Integer direction){
        return new BigDecimal(direction).divide(new BigDecimal(DIRECTION_POINT),2,   BigDecimal.ROUND_HALF_UP).toPlainString();
    }
    public static Integer parseHeight(Double height){
        return new BigDecimal(height).multiply(new BigDecimal(HEIGHT_POINT)).intValue();
    }
    public static String getLatLngByOld(Long point){
        String string = new BigDecimal(point).divide(new BigDecimal(LAT_LNG_POINT)).toPlainString();
        String[] split = string.split("\\.");
        if(split.length<2){
            throw new AnalySocketException(AnalySocketExceptionEmum.SYS_ERROR);
        }
        BigDecimal afterPoint =  new BigDecimal("0."+split[1]).multiply(new BigDecimal(100));
        afterPoint= afterPoint.divide(new BigDecimal(60),10,   BigDecimal.ROUND_HALF_UP);
        BigDecimal value =  new BigDecimal(split[0]).add(afterPoint);
        return value.toPlainString();
    }

    public static Long parseLatLng(String ponit){
        String[] split = ponit.split("\\.");
        if(split.length<2){
            throw new AnalySocketException(AnalySocketExceptionEmum.SYS_ERROR);
        }
        BigDecimal afterPoint =  new BigDecimal("0."+split[1]).multiply(new BigDecimal(60)).divide(new BigDecimal(100),10,   BigDecimal.ROUND_HALF_UP);
        BigDecimal value =  new BigDecimal(split[0]).add(afterPoint).multiply(new BigDecimal(LAT_LNG_POINT));
        return value.longValue();
    }

}
